<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\Common\Constants\PermissionTypeConstants;
use App\Common\Mapper\CommonMenuMapper;

class ChMenuMapper extends CommonMenuMapper
{
    /**
     * 获取超级管理员（创始人）的路由菜单
     * @return array
     */
    public function getSuperAdminRouters($permissionType = PermissionTypeConstants::CUST_HUB,?int $isGuide = null): array
    {
        return $this->model::query()
            ->select($this->menuField)
            ->where('status', $this->model::ENABLE)
            ->where('permission_type',$permissionType)
            ->when($isGuide,function ($query) use ($isGuide){
                $query->where('is_guide',$isGuide);
            })
            ->orderBy('sort', 'desc')
            ->get()->toArray();
    }

    /**
     * 通过菜单ID列表获取菜单数据
     * @param array $ids
     * @return array
     */
    public function getRoutersByIds(array $ids,?int $isGuide = null): array
    {
        return $this->model::query()
            ->select($this->menuField)
            ->whereIn('id', $ids)
            ->where('status', $this->model::ENABLE)
            ->when($isGuide,function ($query) use ($isGuide){
                $query->where('is_guide',$isGuide);
            })
            ->orderBy('sort', 'desc')
            ->get()->toArray();
    }
}